﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Cryptography;
using System.IO;
using System.Text;
using System.Globalization; 
/// <summary>
/// MsgBox 的摘要说明

/// </summary>
public class MsgBox
{
    public MsgBox()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public static void Aert_Alert(string Text)
    {
        string label = "<script  language=javascript>alert('" + Text + "');";
        System.Web.HttpContext.Current.Response.Write(label);

    }

    public static void Aert(string Text, string url)
    {
        string label = "<script  language=javascript>alert('" + Text + "');window.location='" + url + "';</script>";
        System.Web.HttpContext.Current.Response.Write(label);

    }
    public static void Aert_history(string Text, int n)
    {
        string label = "<script  language=javascript>alert('" + Text + "');history.go('" + n + "');</script>";
        System.Web.HttpContext.Current.Response.Write(label);

    }
    /// <summary>
    /// 加密
    /// </summary>
    /// <param name="strText"></param>
    /// <returns></returns>
    public static string JiaMi_Encrypt(string strText)
    {
        string strEncrKey = "songxiud";
        byte[] byKey = null;
        byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
        try
        {
            byKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, strEncrKey.Length));
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            return Convert.ToBase64String(ms.ToArray());
        }
        catch (System.Exception error)
        {
            return "error:" + error.Message + "\r";
        }
    }
    /// <summary>
    /// aspx页面调用的加密
    /// </summary>
    /// <param name="strText"></param>
    /// <returns></returns>
    public static string JiaMiobj_Encrypt(object strText)
    {
        try
        {
            string sKey = "MAY_I114";
            byte[] data = Encoding.UTF8.GetBytes(strText.ToString());
            DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
            DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
            ICryptoTransform desencrypt = DES.CreateEncryptor();
            byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length);
            return BitConverter.ToString(result);
        }
        catch (Exception ex)
        {
            return "";
        }

    }
    /// <summary>
    /// 解密
    /// </summary>
    /// <param name="strText"></param>
    /// <param name="sDecrKey"></param>
    /// <returns></returns>
    public static string JieMi_Decrypt(string strText)
    {
        try
        {
            string sKey = "MAY_I114";
            string[] sInput = strText.Split("-".ToCharArray());
            byte[] data = new byte[sInput.Length];
            for (int i = 0; i < sInput.Length; i++)
            {
                data[i] = byte.Parse(sInput[i], NumberStyles.HexNumber);
            }
            DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
            DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
            ICryptoTransform desencrypt = DES.CreateDecryptor();
            byte[] result = desencrypt.TransformFinalBlock(data, 0, data.Length);
            return Encoding.UTF8.GetString(result);
        }
        catch (Exception em)
        {
         return "";
        }


    }
    
}
